﻿using Godot;

namespace VectorSurvivors.GameWorld;

[GlobalClass]
public partial class ItemStack : Resource
{
    public int Count { get; set; }
    public Item Item { get; set; }
    public bool IsValid => Count > 0;
    

    public Inventory CurrentInventory { get; internal set; }
    
    public bool CanMergeTo(ItemStack other)
    {
        return other.Item == Item;
    }
    
    public void MergeTo(ItemStack other)
    {
        other.Count += Count;
        Count = 0;
            
        if (!IsValid)
        {
            CurrentInventory = null;
        }
        
        CurrentInventory?.Notify_StackMerged(this);
    }
}